package com.retailers.generator.controller;


import com.retailers.generator.bean.TableBean;
import com.retailers.generator.service.MybatisGenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController ()
@RequestMapping("/code/generator")
public class GeneratorApiController {

	@Autowired
	MybatisGenService generatorService;


	@GetMapping("/tablesList")
	List<TableBean> list() throws Exception {
		List<TableBean> list = generatorService.tablesList();
		return list;
	}

	@RequestMapping("/genCode")
	public void genCode(@RequestBody List<TableBean> tableNames) throws Exception {
		 generatorService.genCode(tableNames);

	}



//
//	@ResponseBody
//	@PostMapping("/update")
//	R update(@RequestParam Map<String, Object> map) {
//		try {
//			PropertiesConfiguration conf = new PropertiesConfiguration("generator.properties");
//			conf.setProperty("author", map.get("author"));
//			conf.setProperty("email", map.get("email"));
//			conf.setProperty("package", map.get("package"));
//			conf.setProperty("autoRemovePre", map.get("autoRemovePre"));
//			conf.setProperty("tablePrefix", map.get("tablePrefix"));
//			conf.save();
//		} catch (ConfigurationException e) {
//			return R.error("保存配置文件出错");
//		}
//		return R.ok();
//	}
}
